VERSION 5.00
Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCTL.OCX"
Object = "{86CF1D34-0C5F-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCT2.OCX"
Begin VB.Form FrmHSSV 
   BorderStyle     =   3  'Fixed Dialog
   Caption         =   "HSSV"
   ClientHeight    =   8085
   ClientLeft      =   45
   ClientTop       =   375
   ClientWidth     =   12150
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MinButton       =   0   'False
   ScaleHeight     =   8085
   ScaleWidth      =   12150
   ShowInTaskbar   =   0   'False
   StartUpPosition =   3  'Windows Default
   Begin VB.Frame Frame 
      Caption         =   "Thong tin chi tiet"
      Height          =   7455
      Left            =   4200
      TabIndex        =   0
      Top             =   360
      Width           =   7815
      Begin VB.OptionButton optGioiTinh 
         Caption         =   "Nu"
         Height          =   255
         Index           =   1
         Left            =   3600
         TabIndex        =   34
         Top             =   3360
         Width           =   1335
      End
      Begin VB.OptionButton optGioiTinh 
         Caption         =   "Nam"
         Height          =   255
         Index           =   0
         Left            =   1560
         TabIndex        =   33
         Top             =   3360
         Value           =   -1  'True
         Width           =   1335
      End
      Begin MSComCtl2.DTPicker dtNgaySinh 
         Height          =   375
         Left            =   1560
         TabIndex        =   32
         Top             =   2760
         Width           =   2055
         _ExtentX        =   3625
         _ExtentY        =   661
         _Version        =   393216
         Format          =   98238465
         CurrentDate     =   40845
      End
      Begin VB.TextBox txtTenDoiTuong 
         Height          =   375
         Left            =   1560
         Locked          =   -1  'True
         TabIndex        =   30
         Top             =   1320
         Width           =   4095
      End
      Begin VB.CommandButton btnChonDoiTuong 
         Caption         =   "..."
         Height          =   375
         Left            =   5760
         TabIndex        =   29
         Top             =   1320
         Width           =   375
      End
      Begin VB.TextBox txtGhiChu 
         Height          =   855
         Left            =   1560
         MultiLine       =   -1  'True
         TabIndex        =   26
         Top             =   5640
         Width           =   5895
      End
      Begin VB.TextBox txtTenMe 
         Height          =   375
         Left            =   1560
         TabIndex        =   25
         Top             =   5160
         Width           =   4575
      End
      Begin VB.TextBox txtHoKhauTT 
         Height          =   375
         Left            =   1560
         TabIndex        =   22
         Top             =   4200
         Width           =   5895
      End
      Begin VB.TextBox txtTenCha 
         Height          =   375
         Left            =   1560
         TabIndex        =   21
         Top             =   4680
         Width           =   4575
      End
      Begin VB.TextBox txtDanToc 
         Height          =   375
         Left            =   1560
         TabIndex        =   17
         Top             =   3720
         Width           =   2055
      End
      Begin VB.TextBox txtTenSV 
         Height          =   375
         Left            =   1560
         TabIndex        =   15
         Top             =   2280
         Width           =   2055
      End
      Begin VB.CommandButton btnChonLop 
         Caption         =   "..."
         Height          =   375
         Left            =   5760
         TabIndex        =   14
         Top             =   840
         Width           =   375
      End
      Begin VB.TextBox txtMaSV 
         Height          =   375
         Left            =   1560
         TabIndex        =   12
         Top             =   360
         Width           =   2055
      End
      Begin VB.TextBox txtTenLop 
         Height          =   375
         Left            =   1560
         Locked          =   -1  'True
         TabIndex        =   7
         Top             =   840
         Width           =   4095
      End
      Begin VB.TextBox txtHoDem 
         Height          =   375
         Left            =   1560
         TabIndex        =   6
         Top             =   1800
         Width           =   2055
      End
      Begin VB.CommandButton btnNhapMoi 
         Caption         =   "Nhap moi"
         Height          =   375
         Left            =   2280
         TabIndex        =   5
         Top             =   6720
         Width           =   1215
      End
      Begin VB.CommandButton btnThem 
         Caption         =   "Them"
         Height          =   375
         Left            =   3600
         TabIndex        =   4
         Top             =   6720
         Width           =   1215
      End
      Begin VB.CommandButton btnXoa 
         Caption         =   "Xoa"
         Height          =   375
         Left            =   4920
         TabIndex        =   3
         Top             =   6720
         Width           =   1215
      End
      Begin VB.CommandButton btnCapNhap 
         Caption         =   "Cap nhat"
         Height          =   375
         Left            =   6240
         TabIndex        =   2
         Top             =   6720
         Width           =   1215
      End
      Begin VB.CommandButton btnChon 
         Caption         =   "Chon"
         Height          =   375
         Left            =   120
         TabIndex        =   1
         Top             =   6720
         Width           =   1215
      End
      Begin VB.Label Label9 
         Caption         =   "Doi tuong"
         Height          =   255
         Left            =   360
         TabIndex        =   31
         Top             =   1440
         Width           =   975
      End
      Begin VB.Label Label11 
         Caption         =   "Ghi chu"
         Height          =   255
         Left            =   360
         TabIndex        =   28
         Top             =   5760
         Width           =   975
      End
      Begin VB.Label Label10 
         Caption         =   "Ten me"
         Height          =   255
         Left            =   360
         TabIndex        =   27
         Top             =   5280
         Width           =   975
      End
      Begin VB.Label Label8 
         Caption         =   "Ho khau TT"
         Height          =   255
         Left            =   360
         TabIndex        =   24
         Top             =   4320
         Width           =   975
      End
      Begin VB.Label Label7 
         Caption         =   "Ten cha"
         Height          =   255
         Left            =   360
         TabIndex        =   23
         Top             =   4800
         Width           =   975
      End
      Begin VB.Label Label6 
         Caption         =   "Gioi tinh"
         Height          =   255
         Left            =   360
         TabIndex        =   20
         Top             =   3360
         Width           =   975
      End
      Begin VB.Label Label5 
         Caption         =   "Ngay sinh"
         Height          =   255
         Left            =   360
         TabIndex        =   19
         Top             =   2880
         Width           =   975
      End
      Begin VB.Label Label4 
         Caption         =   "Dan toc"
         Height          =   255
         Left            =   360
         TabIndex        =   18
         Top             =   3840
         Width           =   975
      End
      Begin VB.Label Label3 
         Caption         =   "Ten SV"
         Height          =   255
         Left            =   360
         TabIndex        =   16
         Top             =   2400
         Width           =   975
      End
      Begin VB.Label Label2 
         Caption         =   "MaSV"
         Height          =   255
         Left            =   360
         TabIndex        =   13
         Top             =   480
         Width           =   975
      End
      Begin VB.Label lblStation 
         Caption         =   "Lop"
         Height          =   255
         Left            =   360
         TabIndex        =   9
         Top             =   960
         Width           =   975
      End
      Begin VB.Label Label1 
         Caption         =   "Ho Dem"
         Height          =   255
         Left            =   360
         TabIndex        =   8
         Top             =   1920
         Width           =   975
      End
   End
   Begin MSComctlLib.ListView lstvData 
      Height          =   7455
      Left            =   120
      TabIndex        =   10
      Top             =   480
      Width           =   3975
      _ExtentX        =   7011
      _ExtentY        =   13150
      View            =   3
      LabelEdit       =   1
      LabelWrap       =   -1  'True
      HideSelection   =   -1  'True
      FullRowSelect   =   -1  'True
      GridLines       =   -1  'True
      _Version        =   393217
      ForeColor       =   -2147483640
      BackColor       =   -2147483643
      Appearance      =   1
      NumItems        =   0
   End
   Begin VB.Label Label 
      Caption         =   "Danh sach sinh vien"
      Height          =   255
      Index           =   0
      Left            =   240
      TabIndex        =   11
      Top             =   120
      Width           =   4095
   End
End
Attribute VB_Name = "FrmHSSV"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit

Private WithEvents formLop As FrmLop
Attribute formLop.VB_VarHelpID = -1
Private WithEvents formDiemDoiTuong As FrmDiemDoiTuong
Attribute formDiemDoiTuong.VB_VarHelpID = -1
Private m_sMaLop As String
Private m_sMaDT As String
Private m_objHSSV As clsHSSV
Private m_ObjADORst  As ADODB.Recordset
Public EnableBtnChon As Boolean
Event EVENTChooseItem(ByVal masv As String, ByVal HoTenSV As String)

Private Sub btnCapNhap_Click()
    Dim objHSSVDto As clsHSSV
    
    Set m_objHSSV = New clsHSSV
    Set objHSSVDto = New clsHSSV
    
    objHSSVDto.masv = Trim(txtMaSV.Text)
    objHSSVDto.MaLop = Trim(m_sMaLop)
    objHSSVDto.MaDT = Trim(m_sMaDT)
    objHSSVDto.HoDem = Trim(txtHoDem.Text)
    objHSSVDto.tensv = Trim(txtTenSV.Text)
    objHSSVDto.NSinh = dtNgaySinh.Value
    objHSSVDto.GioiTinh = IIf(optGioiTinh(0).Value, True, False)
    objHSSVDto.DToc = Trim(txtDanToc.Text)
    objHSSVDto.HoKhauTT = Trim(txtHoKhauTT.Text)
    objHSSVDto.TenCha = Trim(txtTenCha.Text)
    objHSSVDto.TenMe = Trim(txtTenMe.Text)
    objHSSVDto.Ghichu = Trim(txtGhiChu.Text)
    
    If m_objHSSV.Update(objHSSVDto) Then
        LoadData
        MsgBox GetReport("CapNhat", "ThanhCong"), vbInformation, "ThongBao"
    Else
        MsgBox GetReport("CapNhat", "ThatBai"), vbCritical, "ThongBao"
    End If
End Sub

Private Sub btnChon_Click()
    If Not IsAnySelectedItem(lstvData) Then Exit Sub
    RaiseEvent EVENTChooseItem(txtMaSV.Text, Trim(txtHoDem.Text) & " " & Trim(txtTenSV.Text))
    Unload Me
End Sub

Private Sub btnChonDoiTuong_Click()
    Set formDiemDoiTuong = New FrmDiemDoiTuong
    formDiemDoiTuong.EnableBtnChon = True
    formDiemDoiTuong.Show 1, Me
End Sub

Private Sub btnChonLop_Click()
    Set formLop = New FrmLop
    formLop.EnableBtnChon = True
    formLop.Show 1, Me
End Sub

Private Sub ResetFields()
    m_sMaLop = ""
    m_sMaDT = ""
    txtTenLop.Text = ""
    txtTenDoiTuong.Text = ""
    txtMaSV.Text = ""
    txtHoDem.Text = ""
    txtTenSV.Text = ""
    'dtNgaySinh.value= DateTime
    optGioiTinh.item(0).Value = True
    txtDanToc.Text = ""
    txtHoKhauTT.Text = ""
    txtTenCha.Text = ""
    txtTenMe.Text = ""
    txtGhiChu.Text = ""
End Sub

Private Sub btnNhapMoi_Click()
    ResetFields
    txtMaSV.Locked = False
End Sub

Private Sub btnThem_Click()
    Dim objHSSVDto As clsHSSV
    Dim errText As String
    
    If Not ValidateInput(errText) Then
        MsgBox errText, vbCritical, "ThongBao"
        Exit Sub
    End If
    
    Set m_objHSSV = New clsHSSV
    Set objHSSVDto = New clsHSSV
    
    objHSSVDto.masv = Trim(txtMaSV.Text)
    objHSSVDto.MaLop = Trim(m_sMaLop)
    objHSSVDto.MaDT = Trim(m_sMaDT)
    objHSSVDto.HoDem = Trim(txtHoDem.Text)
    objHSSVDto.tensv = Trim(txtTenSV.Text)
    objHSSVDto.NSinh = dtNgaySinh.Value
    objHSSVDto.GioiTinh = IIf(optGioiTinh(0).Value, True, False)
    objHSSVDto.DToc = Trim(txtDanToc.Text)
    objHSSVDto.HoKhauTT = Trim(txtHoKhauTT.Text)
    objHSSVDto.TenCha = Trim(txtTenCha.Text)
    objHSSVDto.TenMe = Trim(txtTenMe.Text)
    objHSSVDto.Ghichu = Trim(txtGhiChu.Text)
    
    If m_objHSSV.Insert(objHSSVDto) Then
        LoadData
        ResetFields
        MsgBox GetReport("Them", "ThanhCong"), vbInformation, "ThongBao"
    Else
        MsgBox GetReport("Them", "ThatBai"), vbCritical, "ThongBao"
    End If
End Sub

Private Sub LoadData()
    Dim i As Integer
    Dim vLstViewItem As ListItem
    
    Set m_objHSSV = New clsHSSV
    Set m_ObjADORst = m_objHSSV.SelectAll
    lstvData.ListItems.Clear
    i = 1
    
    Do While Not m_ObjADORst.EOF
        Set vLstViewItem = lstvData.ListItems.Add(i)
        vLstViewItem = m_ObjADORst!masv
        vLstViewItem.SubItems(1) = m_ObjADORst!tensv
        vLstViewItem.SubItems(2) = m_ObjADORst!TenLop
        m_ObjADORst.MoveNext
        i = i + 1
    Loop

End Sub

Private Sub btnXoa_Click()
    If Trim(txtMaSV.Text) = "" Then Exit Sub
    
    Set m_objHSSV = New clsHSSV
     
    If MsgBox(GetReport("Xoa", "XacNhan"), vbInformation + vbOKCancel, "ThongBao") = vbOK Then
        If m_objHSSV.Delete(Trim(txtMaSV.Text)) Then
            LoadData
            ResetFields
            MsgBox GetReport("Xoa", "ThanhCong"), vbInformation, "ThongBao"
        Else
            MsgBox GetReport("Xoa", "ThatBai"), vbCritical, "ThongBao"
        End If
    End If
End Sub

Private Sub Form_Load()
    Init
    LoadData
    Call ClearSelection(lstvData)
End Sub

Public Sub Init()
    lstvData.ColumnHeaders.Clear
    lstvData.ColumnHeaders.Add , , "Ma SV", lstvData.Width / 3
    lstvData.ColumnHeaders.Add , , "Ten SV", lstvData.Width / 3
    lstvData.ColumnHeaders.Add , , "Lop", lstvData.Width / 3
    
    If EnableBtnChon Then
        btnChon.Enabled = True
    Else
        btnChon.Enabled = False
    End If
End Sub

Private Sub formLop_EVENTChooseItem(ByVal MaLop As String, ByVal TenLop As String)
    m_sMaLop = MaLop
    txtTenLop.Text = TenLop
End Sub

Private Sub formDiemDoiTuong_EVENTChooseItem(ByVal MaDT As String, ByVal TenDT As String)
    m_sMaDT = MaDT
    txtTenDoiTuong.Text = TenDT
End Sub

Public Function ValidateInput(ByRef errText As String) As Boolean
    ValidateInput = True
    If Trim(txtMaSV.Text) = "" Then
        errText = "Ban chua nhap ma SV"
        ValidateInput = False
        Exit Function
    End If
    If Trim(txtTenLop.Text) = "" Then
        errText = "Ban chua chon lop"
        ValidateInput = False
        Exit Function
    End If
    If Trim(txtTenDoiTuong.Text) = "" Then
        errText = "Ban chua chon doi tuong"
        ValidateInput = False
        Exit Function
    End If
    If Trim(txtHoDem.Text) = "" Then
        errText = "Ban chua nhap ho dem"
        ValidateInput = False
        Exit Function
    End If
    If Trim(txtTenSV.Text) = "" Then
        errText = "Ban chua nhap ten  sinh vien"
        ValidateInput = False
        Exit Function
    End If
End Function

Private Sub lstvData_ItemClick(ByVal item As MSComctlLib.ListItem)
    Set m_ObjADORst = m_objHSSV.SelectByID(item)
    If Not m_ObjADORst Is Nothing Then
        txtMaSV.Text = m_ObjADORst!masv
        m_sMaLop = m_ObjADORst!MaLop
        m_sMaDT = m_ObjADORst!MaDT
        txtTenLop.Text = m_ObjADORst!TenLop
        txtTenDoiTuong.Text = m_ObjADORst!TenDT
        txtHoDem.Text = m_ObjADORst!HoDem
        txtTenSV.Text = m_ObjADORst!tensv
        dtNgaySinh.Value = m_ObjADORst!NSinh
        If m_ObjADORst!GioiTinh = True Then
            optGioiTinh(0).Value = True
            optGioiTinh(1).Value = False
        Else
            optGioiTinh(0).Value = False
            optGioiTinh(1).Value = True
        End If
        txtDanToc.Text = m_ObjADORst!DToc
        txtHoKhauTT.Text = m_ObjADORst!HoKhauTT
        txtTenCha.Text = m_ObjADORst!TenCha
        txtTenMe.Text = m_ObjADORst!TenMe
        txtGhiChu.Text = m_ObjADORst!Ghichu

        txtMaSV.Locked = True
    End If
End Sub

